package com.dw.etl.core.service;

import com.dw.etl.common.util.SnowflakeIdWorker;
import com.dw.etl.common.vo.PaginationVO;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.BaseSdItemService;
import com.dw.etl.core.mapper.BaseSdItemMapper;
import com.dw.etl.core.bean.model.BaseSdItem;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * baseSdItem服务实现类
 * Created by hozeData on 2021/05/21.
 */
@Service
@Transactional
public class BaseSdItemServiceImpl implements BaseSdItemService{

    private static final Logger LOGGER = LoggerFactory.getLogger(BaseSdItemServiceImpl.class);

    @Autowired
    private BaseSdItemMapper baseSdItemMapper;

    @Override
    public int insert(BaseSdItem baseSdItem) {
        if(baseSdItem.getIdSdItem()==null){
            Long uuid32 = SnowflakeIdWorker.getId();
            baseSdItem.setIdSdItem(uuid32);
        }
        return baseSdItemMapper.insert(baseSdItem);
    }

    @Override
    public int insertSelective(BaseSdItem baseSdItem)  {
        if(baseSdItem.getIdSdItem()==null){
            Long uuid32 = SnowflakeIdWorker.getId();
            baseSdItem.setIdSdItem(uuid32);
        }
        return baseSdItemMapper.insertSelective(baseSdItem);
    }

    @Override
    public int deleteById(Long idSdItem)  {
        return baseSdItemMapper.deleteByPrimaryKey(idSdItem);
    }

    @Override
    public int updateByIdSelective(BaseSdItem baseSdItem)  {

        return baseSdItemMapper.updateByPrimaryKeySelective(baseSdItem);
    }

    @Override
    public int updateById(BaseSdItem baseSdItem)  {
        return baseSdItemMapper.updateByPrimaryKey(baseSdItem);
    }

    @Override
    public BaseSdItem getById(Long idSdItem)  {
        return baseSdItemMapper.selectByPrimaryKey(idSdItem);
    }

    @Override
    public List<BaseSdItem> findByModel(BaseSdItem baseSdItem)  {
        return baseSdItemMapper.findByModel(baseSdItem);
    }

    @Override
    public PaginationVO<BaseSdItem> findPageByModel(BaseSdItem baseSdItem, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<BaseSdItem> quesList = baseSdItemMapper.findByModel(baseSdItem);
        PageInfo<BaseSdItem> pageInfo = new PageInfo<>(quesList);
        PaginationVO<BaseSdItem> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }





}
